﻿// HSS.Interlink.Web.FileUpload.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.html)
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2012
// ----------------------------------------------------------------------------
// File:       FileUpload.cs
// Author:     HSS\gbanta
// Created:    07/16/2011
// Modified:   07/22/2011
// ----------------------------------------------------------------------------
namespace HSS.Interlink.Web
{
	#region Using Directives
	using System;
	using System.Configuration;
	using System.Web;
	using System.Web.SessionState;
	using System.Diagnostics;

	#endregion

	#region FileUpload
	/// <summary>
	/// FileUpload processes upload file requests syncronously.
	/// </summary>
	public sealed class FileUpload : InterlinkHandler
	{
		#region Constructors
		/// <summary>
		/// Constructor
		/// </summary>
		public FileUpload()
		{

		}
		#endregion

		#region InterlinkHandler
		/// <summary>
		/// This is called by the ASP.NET Runtime or from <see cref="FileUploadAsync"/>.
		/// </summary>
		/// <param name="context">The current <see cref="HttpContext"/> for the request being processed</param>
		public override void ProcessRequest(HttpContext context)
		{
			FileQuery query;
			if (!this.TryParseQuery(context, out query))
				return;

			IUploadHandler handler = this.GetHandler<IUploadHandler>(query.HandlerKey);
			if (null == handler)
			{
				this.Fault(context, StatusCode_File_Not_Found);
				return;
			}

			handler.Upload(context, query);
		}
		#endregion
	}
	#endregion
}